package it.polimi.traveldream.ejb.entities;

import it.polimi.traveldream.ejbclient.dtos.ExcursionDTO;

import java.io.Serializable;

import javax.persistence.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the excursion database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name=Excursion.FIND_EXCURSIONS_AVAILABLE,
			query="SELECT e FROM Excursion e WHERE e.startTrip >= :start AND e.endTrip <= :end AND e.maxAvailability - e.reservations >= :reservations"),
	@NamedQuery(name=Excursion.FIND_EXCURSIONS,
			query="SELECT e FROM Excursion e WHERE e.overpast = :overpast")	

})
public class Excursion implements Serializable {
	private static final long serialVersionUID = -8256170406985985040L;
	public static final String FIND_EXCURSIONS_AVAILABLE = "Excursion.findExcursionsAvailable";
	public static final String FIND_EXCURSIONS = "Excursion.findExcursions";
	private int id;
	private String description;
	private Date endTrip;
	private int maxAvailability;
	private String organizer;
	private boolean overpast;
	private float pathKm;
	private BigDecimal price;
	private int reservations;
	private String startAddress;
	private Date startTrip;
	private List<Travelpackage> travelpackages;

	public Excursion() {
		super();
	}

	public Excursion(ExcursionDTO excursion) {
		super();
		this.id = excursion.getId();
		this.description = excursion.getDescription();
		this.endTrip = excursion.getEndTrip();
		this.maxAvailability = excursion.getMaxAvailability();
		this.organizer = excursion.getOrganizer();
		this.overpast = excursion.isOverpast();
		this.pathKm = excursion.getPathKm();
		this.price = excursion.getPrice();
		this.reservations = excursion.getReservations();
		this.startAddress = excursion.getStartAddress();
		this.startTrip = excursion.getStartTrip();
	}


	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}


	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	@Temporal(TemporalType.TIMESTAMP)
	public Date getEndTrip() {
		return this.endTrip;
	}

	public void setEndTrip(Date endTrip) {
		this.endTrip = endTrip;
	}


	public int getMaxAvailability() {
		return this.maxAvailability;
	}

	public void setMaxAvailability(int maxAvailability) {
		this.maxAvailability = maxAvailability;
	}


	public String getOrganizer() {
		return this.organizer;
	}

	public void setOrganizer(String organizer) {
		this.organizer = organizer;
	}


	public boolean getOverpast() {
		return this.overpast;
	}

	public void setOverpast(boolean overpast) {
		this.overpast = overpast;
	}


	public float getPathKm() {
		return this.pathKm;
	}

	public void setPathKm(float pathKm) {
		this.pathKm = pathKm;
	}


	public BigDecimal getPrice() {
		return this.price;
	}

	public void setPrice(BigDecimal price) {
		this.price = price;
	}


	public int getReservations() {
		return this.reservations;
	}

	public void setReservations(int reservations) {
		this.reservations = reservations;
	}


	public String getStartAddress() {
		return this.startAddress;
	}

	public void setStartAddress(String startAddress) {
		this.startAddress = startAddress;
	}


	@Temporal(TemporalType.TIMESTAMP)
	public Date getStartTrip() {
		return this.startTrip;
	}

	public void setStartTrip(Date startTrip) {
		this.startTrip = startTrip;
	}


	//bi-directional many-to-many association to Travelpackage
	@ManyToMany(mappedBy="excursions")
	public List<Travelpackage> getTravelpackages() {
		return this.travelpackages;
	}

	public void setTravelpackages(List<Travelpackage> travelpackages) {
		this.travelpackages = travelpackages;
	}

}